<?php
namespace APP\C;

class Index extends Controller
{

    public function indexAction()
    {
        $this->view->render('main.tpl');
    }


    /**
     * 修改密码
     */
    public function pwdAction()
    {
        $this->view->render('pwd.tpl');
    }
    public function pwdexeAction()
    {
        $result = new \SF\Result();
        $pwdInput = new \APP\PUT\Pwd($this->request->getPost());
        if ($pwdInput->isValid()) {
            $where = 'email="'. \SF\Session\Session::get(self::SESS_ADMIN) .'"';
            $sql = 'SELECT password FROM admin_user WHERE '. $where;
            if (md5($pwdInput->oldpass) == $this->db->fetchOne($sql)) {
                $sql = 'UPDATE admin_user SET password="'. md5($pwdInput->newpass) .'" WHERE '. $where;
                $this->db->query($sql);
                $result->setValid();
                \SF\Session\Session::destroy(self::SESS_ADMIN);
            } else {
                $result->setMessage('原密码错误');
            }
        } else {
            $result->setMessage($pwdInput->getMessage());
        }

        echo $result->getByJson();
        exit;
    }




    /**
     * 分页示例
     */
	public function pagetestAction()
	{
        $perPage = 20;
        $pageRange = 10;

		// 参数
		$page = $this->request->getParam('page', 1);

		// 数据
		$sql = 'SELECT SQL_CALC_FOUND_ROWS * FROM t_note';
		$data = $this->getDb()->fetchAll($sql);
		$sql = 'SELECT FOUND_ROWS()';
		$count = $this->getDb()->fetchOne($sql);
        $count = 100;
		
		// 分页
		$p = new \SF\Paginator($page, $count, $perPage, $pageRange);

		// 模板
		$this->view->page = $p->getRender();
		$this->view->data = $data;
		$this->view->render('test.tpl');
	}
}